
import argparse
from pathlib import Path
from abi2img.abi import ABI, SNV


def run_abi_cmd(args):
    args_vars = vars(args)
    abi = ABI(**args_vars)
    bytes_io = abi.run()
    with open(args.outdir/abi.img_name, 'wb') as writer:
        writer.write(bytes_io.getvalue())


def main():
    parser = argparse.ArgumentParser(description='Auto CNVKit')
    parser.add_argument('--abi_file', '-i', type=Path, required=True, help='input, sanger abi file')
    parser.add_argument('--ref_dir', '-r', type=Path, required=True, help='input, reference fasta by chromosome directory ')
    parser.add_argument('--snv', '-s', required=True, type=SNV.parse_str, help='input, snv info in format: "sample:gene:chrom:pos:ref:alt"')
    parser.add_argument('--outdir', '-o', type=Path, required=True, help='parameter, output directory')
    parser.set_defaults(func=run_abi_cmd)
    args = parser.parse_args()
    args.func(args)
